<?php


class HttpRequest {

    private $post;
    private $get;
    private $session;
    private $file;
    private $cookie;
    private $web_page;
    private $action_page;
    private $forward = null;

    public function __construct($web_page, $action_page, &$post, &$get, &$session, &$file, &$cookie, &$http_forward) {
        $this->web_page = $web_page;
        $this->action_page = $action_page;
        $this->post = $post;
        $this->get = $get;
        $this->session = &$session;
        $this->file = $file;
        $this->cookie = &$cookie;
        $this->forward = &$http_forward;
      
    }

    public function getNumber($name, $value_escape = null) {
        $result = $this->get($name);
        if ($result != null && is_numeric($result)) {
            return $result;
        } else {
            return $value_escape;
        }
    }
    
    public function getIntNumber($name) {
        $result = $this->get($name);
        if ($result != null && ctype_digit($result)) {
            return intval($result);
        } else {
            return 0;
        }
    }

    public function get($name, $value_escape = null) {
        if (isset($this->post) && isset($this->post[$name])) {
            return (is_string($this->post[$name]) ? trim($this->post[$name]) : $this->post[$name]);
        }else if (isset($this->get) && isset($this->get[$name])) {
            return (is_string($this->get[$name]) ? trim($this->get[$name]) : $this->get[$name]);
        }else if (!is_null($value_escape)) {
            return $value_escape;
        }else {
            return null;
        }
    }

    public function getSession($name, $default_value = null) {
        if (isset($this->session) && isset($this->session[$name])) {
            return $this->session[$name];
        } else if (!is_null($default_value)) {
            return $default_value;
        } else {
            return null;
        }
    }

    public function getSessionObject() {
       return $this->session;
    }

    public function setSession($name, $value) {
        $this->session[$name] = $value;
    }

    public function getFile($name) {
        if (isset($this->file) && isset($this->file[$name])) {
            return $this->file[$name];
        } else {
            return null;
        }
    }

    public function getCookie() {
        return $this->cookie;
    }

    public function getWebPage() {
        return $this->web_page;
    }

    public function getActionPage() {
        return $this->action_page;
    }

    public function setAttribute($name, $value) {
        $this->forward->assign($name, $value);
    }

    public function forward($page) {
        $this->forward->forward($page);
    }

}
